<template>
<div v-if="viewLoading" class="ivu-card ivu-card-bordered ivu-card-dis-hover">
  <div class="ivu-card-head">
    <p>{{ $route.meta.title }}</p>
    <button type="button" class="ivu-btn ivu-btn-ghost" @click="$router.go(-1);"><span>返回</span></button>
  </div>

  <div class="ivu-card-head">
    备注：商户总数与一周内完成进货总额度都需加上当前账号<br/>
    如: xx:20(即是2+0+18=20)【一周内完成进货如同此例子】<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xx: 0(此为1个)<br/>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xx: 18(此为1个)<br/>
  </div>
  <div class="ivu-card-body">
    <Tree :data="models" :load-data="loadData"/>
  </div>
</div>
</template>
<script>
import qs from 'qs';
import { Tree, Message } from 'iview';
import ajaxiView from '@/utils/ajaxiView';
import auth from '@/utils/auth';

export default {
  components: {
    [Tree.name]: Tree
  },
  data() {
    return {
      token: auth.getToken(),
      apiConfig: {},
      viewLoading: false,
      models: []
    };
  },
  methods: {
    loadData(item, callback) {
      ajaxiView.get('/user/backstage/team/'+item.id+'?token='+this.token).then(function(result) {
        var data = [];
        if(result !== false && typeof(result.models) != 'undefined') {
          for(var m in result.models) {
            data.push({
              title: result.models[m].account + ', 商户总数: ' + result.models[m]['team_total'] + ', 一周内完成进货总额度: ' + result.models[m]['this_week_trade_buy_total'],
              id: result.models[m].user_id,
              loading: false,
              children: []
           });
          }
        } else {
          data.push({
            title: '无下级数据'
          });
        }
        callback(data);
      });
    },
    getData() {
      this.viewLoading = true;
      this.models.push({
        title:this.$route.query.account,
        id:this.$route.params.id,
        loading: false,
        children:[]
      });
    },
    _initialize() {
      this.getData();
    }
  },
  mounted() {
    this._initialize();
  }
}
</script>
